import request from "@/utils/request";

export const uploadFile = (formData) => {
  return request({
    url: "/media/upload",
    method: "post",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
};

export const newUploadFile = (formData) => {
  return request({
    url: "/file/upload-m3u8",
    method: "post",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
};

// 新增统一上传方法，根据文件类型选择接口
export const upload = (formData) => {
  // 假设formData是FormData对象，文件字段名为'file'
  const file = formData.get("file");
  if (!file) return Promise.reject(new Error("未找到文件"));
  const isVideo = file.type.startsWith("video/");
  if (isVideo) {
    return newUploadFile(formData);
  } else {
    return uploadFile(formData);
  }
};
